<?php include("session.php") ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0041)http://www.ewebvn.com/demo/div-three-col/ -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Wedding studio</title>
</head>
<body>
<?php include("header_admin.php"); ?>

<?php

$valid_formats = array("jpg", "png", "gif", "bmp");
$max_file_size = 1024*1024*10; //100 kb
$count = 0;
if(isset($_GET['t'])){
   $path = "../../upload/albumcuoi/".$_GET['t']."/"; // Upload directory
}
$file_name = array();
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
	// Loop $_FILES to execute all files
	foreach ($_FILES['files']['name'] as $f => $name) {     
	    if ($_FILES['files']['error'][$f] == 4) {
	        continue; // Skip file if any error found
	    }	       
	    if ($_FILES['files']['error'][$f] == 0) {	           
	        if ($_FILES['files']['size'][$f] > $max_file_size) {
	            $message[] = "$name dung lượng quá lớn!.";
	            continue; // Skip large files
	        }
			elseif( ! in_array(strtolower(pathinfo($name, PATHINFO_EXTENSION)), $valid_formats) ){
				$message[] = "$name không đúng định dạng ảnh";
				continue; // Skip invalid file formats
			}
	        else{ // No error found! Move uploaded files 
	            if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name)) {
	            	$count++; // Number of successfully uploaded files
                    array_push($file_name,$name);
	            }
	        }
	    }
	}
}
?>
<style type="text/css">
</style>

</head>
<body>
	<div id="mainWap">
        <h3>Thêm ảnh cưới</h3>
        <p>Dung lượng tối đa của ảnh là 10Mb, định dạng ảnh phải là jpg, png, gif</p>
		<br />
		<br />
		<!-- Multiple file upload html form-->
		<form action="" method="post" enctype="multipart/form-data">
			<input type="file" name="files[]" multiple="multiple" accept="image/*"/>
			<input type="submit" value="Upload"/>
		</form>
        <br />
		<br />
        
		<?php
		# error messages
		if (isset($message)) {
			foreach ($message as $msg) {
				printf("<p>%s</p></ br>\n", $msg);
			}
		}
		# success message
		if($count !=0){
			printf("<p class='status'>Thêm thành công %d ảnh:</p>\n", $count);
            foreach($file_name as $fn){
                printf("<p>%s</p></ br>\n", $fn);
            }
		}
		?>
</div>
</body>




<?php include("footer_admin.php"); ?>
    <!-- end wapper -->

<div style="display:none" id="addthis-extension-script"></div></body><div style="display: none; " id="k1XKb07LtFf3qXDHOv7u5v1C" class="kzlzuwUwKPAvDYR3E7uqB8"></div><div style="display: none; " id="YV8CLCODDDq0pfWQ4qijEZEt_" class="kzlzuwUwKPAvDYR3E7uqB8"></div><div style="display: none; " id="kWRY8_3uCTQWbN_sjCoSQjlEqp" class="kzlzuwUwKPAvDYR3E7uqB8"></div></html>